import java.util.Random;
import java.util.concurrent.*;

/**
 * 演示有返回值的线程池
 */
public class ThreadPoolDemo2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 创建一个线程个数为5的固定大小的线程池
        ExecutorService threadPool = Executors.newFixedThreadPool(5);
        Future<Integer> result = threadPool.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int num = new Random().nextInt(10);
                System.out.println("生成随机数：" + num);
                return num;
            }
        });
        System.out.println("得到线程池返回结果：" + result.get());
        System.out.println("eee");
    }
}
